package com.heima;

import javafx.scene.paint.Color;

public class ShapeState {
    double x, y, width, height;
    double centerX, centerY, radiusX, radiusY;
    double diamondWidth, diamondHeight;
    Color color;
    String text;

    ShapeState(DrawableShape shape) {
        if (shape instanceof RectangleShape) {
            RectangleShape rect = (RectangleShape) shape;
            x = rect.x;
            y = rect.y;
            width = rect.width;
            height = rect.height;
        } else if (shape instanceof EllipseShape) {
            EllipseShape ellipse = (EllipseShape) shape;
            centerX = ellipse.centerX;
            centerY = ellipse.centerY;
            radiusX = ellipse.radiusX;
            radiusY = ellipse.radiusY;
        } else if (shape instanceof DiamondShape) {
            DiamondShape diamond = (DiamondShape) shape;
            centerX = diamond.centerX;
            centerY = diamond.centerY;
            diamondWidth = diamond.width;
            diamondHeight = diamond.height;
        }
        color = shape.getColor();
        text = shape.getText();
    }

    void applyTo(DrawableShape shape) {
        if (shape instanceof RectangleShape) {
            RectangleShape rect = (RectangleShape) shape;
            rect.x = x;
            rect.y = y;
            rect.width = width;
            rect.height = height;
        } else if (shape instanceof EllipseShape) {
            EllipseShape ellipse = (EllipseShape) shape;
            ellipse.centerX = centerX;
            ellipse.centerY = centerY;
            ellipse.radiusX = radiusX;
            ellipse.radiusY = radiusY;
        } else if (shape instanceof DiamondShape) {
            DiamondShape diamond = (DiamondShape) shape;
            diamond.centerX = centerX;
            diamond.centerY = centerY;
            diamond.width = diamondWidth;
            diamond.height = diamondHeight;
        }
        shape.setColor(color);
        shape.setText(text);
    }
}